package com.qing.qingpicturebackend.model.vo;

import cn.hutool.core.util.ObjUtil;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.qing.qingpicturebackend.model.entity.User;
import lombok.Data;
import org.springframework.beans.BeanUtils;

import java.util.Date;

@Data
public class UserVO {
    private Long id;

    /**
     * 账号
     */
    private String userAccount;


    /**
     * 用户昵称
     */
    private String userName;

    /**
     * 用户头像
     */
    private String userAvatar;

    /**
     * 用户简介
     */
    private String userProfile;

    /**
     * 用户角色：user/admin
     */
    private String userRole;

    /**
     * 编辑时间
     */
    private Date editTime;

    /**
     * 创建时间
     */
    private Date createTime;

    /**
     * 更新时间
     */
    private Date updateTime;

    private static final long serialVersionUID = 1L;

    /**
     * VO转对象
     * @param userVO
     * @return
     */
    public static User voToObj(UserVO userVO) {
        if(ObjUtil.isNull(userVO)||userVO.getId()==null){
            return null;
        }
        User user = new User();
        BeanUtils.copyProperties(userVO,user);
        return user;
    }

    /**
     * 对象转VO
     * @param user
     * @return
     */
    public static UserVO objToVO(User user) {
        if(ObjUtil.isNull(user)||user.getId()==null){
            return null;
        }
        UserVO userVO = new UserVO();
        BeanUtils.copyProperties(user,userVO);
        return userVO;
    }
}
